Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Minimum Deletions to Make Character Frequencies Unique (medium)
Problem Statement
Given a string str, return the minimum number of characters you need to delete to make str good.
A good string doesn't contain two different characters with the same frequency.
Examples
Example 1:
- Input: "aabbbb"
- Expected Output: 0
- Justification: In the given string, the frequency of
ais 2, and the frequency ofbis 4. Each character already has a unique frequency. So, no need to delete any character from the string
Example 2:
- Input: "aaaabbbbcc"
- Expected Output: 1
- Justification: The character 'c' appears twice, and 'a' and 'b' appear four times each. To make all frequencies unique, we can delete one occurrence of either 'a' or 'b'. This leaves us with 'a', 'b', and 'c' having frequencies of 3, 4, and 2, respectively.
Example 3:
- Input: "aabbcc"
- Expected Output: 3
- Justification: Here, each character's frequncey is 2. By deleting both
aand 1b, we can make frequency unique.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Rotting Oranges
Solution: Minimum Deletions to Make Character Frequencies Unique
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself